package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.mapper.BusinessAbodeMapper;
import com.koron.css2.baseConfig.queryBean.BankQueryBean;
import com.koron.css2.baseConfig.vo.SelectVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 营业所下拉框
 * 
 * @author 甄玉晴
 *
 */
public class BusinessAbodeSelect implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		@SuppressWarnings("rawtypes")
		MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", List.class);
		try {		
			BusinessAbodeMapper mapper = factory.getMapper(BusinessAbodeMapper.class,"_default");
			
			String companyNo=userInfo.getCurWaterCode();
			if(StringUtils.isEmpty(companyNo)) {
				BankQueryBean selectBean = JsonUtils.objectToPojo(req.getData(), BankQueryBean.class);
            	companyNo=selectBean.getCompanyNo();
            }
			//获取下拉框
			List<SelectVO> list = mapper.businessAbodeSelect(companyNo);
			info.setData(list);
			return info;
		} catch (Exception e) {
			logger.error("营业所查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "营业所查询失败", null);
		}

	}
}
